package one.stand.service.impl;

import com.github.pagehelper.PageHelper;
import one.stand.model.CompanyCouponModel;
import one.stand.model.ResultModel;
import one.stand.request.CompanyCouponRequest;
import one.stand.response.CompanyCouponResponse;
import one.stand.service.CompanyCouponService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: QIK
 * @CreateDate: 2019/6/25 9:23
 */
@Service
public class CompanyCouponServiceImpl extends PublicBaseService implements CompanyCouponService {
    @Override
    public ResultModel<List<CompanyCouponResponse>> selectGoodsTypeAndCompanyNameByCompanyId(CompanyCouponRequest request) {
        if(null==request.getCompanyId()){
            return ResultModel.checkParamFail();
        }
        PageHelper.startPage(request.getPageNum(),request.getPageSize());
        List<CompanyCouponModel> outModelList=companyCouponMapper.selectGoodsTypeAndCompanyNameListByCompanyId(request.getCompanyId());
        if(outModelList.size()<=0){
            return ResultModel.noData();
        }
        List<CompanyCouponResponse> responseList=new ArrayList<>();
        outModelList.forEach(ml->{
            CompanyCouponResponse response=new CompanyCouponResponse();
            BeanUtils.copyProperties(ml,response);
            responseList.add(response);
        });
        return ResultModel.success(responseList);
    }
}
